import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tiktokadult/alert_business/video/share_video_dialog.dart';
import 'package:tiktokadult/assets_tool/images.dart';
import 'package:tiktokadult/hj_model/video_model.dart';
import 'package:tiktokadult/hj_page/mine_business/collec_history_buy/col_his_buy_sub_page.dart';
import 'package:tiktokadult/hj_utils/api_service/common_service.dart';
import 'package:tiktokadult/hj_utils/api_service/mine_service.dart';
import 'package:tiktokadult/hj_utils/widget_utils.dart';

class PostDetailOperationView extends StatefulWidget {
  final VideoModel model;

  const PostDetailOperationView({super.key, required this.model});

  @override
  State<PostDetailOperationView> createState() => _PostDetailOperationViewState();
}

class _PostDetailOperationViewState extends State<PostDetailOperationView> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 24,
      margin: EdgeInsets.only(bottom: 18.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Image.asset("count_eye_gray.png".communityPath, width: 20, height: 20),
              const SizedBox(width: 2),
              Text(
                widget.model.pageViewCount?.humanizeFormat ?? "",
                style: TextStyle(
                  color: Color(0xff989898),
                  fontSize: 12,
                ),
              ),
            ],
          ),
          40.sizeBoxW,
          GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: () async {
              final temp = widget.model.vidStatus?.hasLiked ?? false;
              final count = widget.model.likeCount ?? 0;
              bool res;
              if (temp) {
                res = await CommonService.cancelLike(widget.model.id ?? '', LoadDataType.post.collectType);
              } else {
                res = await CommonService.sendLike(widget.model.id ?? '', LoadDataType.post.collectType);
              }
              if (res) {
                widget.model.vidStatus?.hasLiked = !temp;
                widget.model.likeCount = temp ? count - 1 : count + 1;
                setState(() {});
              }
            },
            child: Row(
              children: [
                Image.asset(
                  widget.model.vidStatus?.hasLiked == true ? "like_red.png".communityPath : "like_empty_gray.png".communityPath,
                  width: 20,
                  height: 20,
                ),
                5.w.sizeBoxW,
                Text(
                  widget.model.likeCount?.humanizeFormatDefault("喜欢") ?? '',
                  style: TextStyle(color: Color(0xff989898), fontSize: 14.sp),
                ),
              ],
            ),
          ),
          40.sizeBoxW,
          // GestureDetector(
          //   behavior: HitTestBehavior.translucent,
          //   onTap: () async {
          //     final collectCount = widget.model.collectCount ?? 0;
          //     final hasCollect = widget.model.hasCollected;
          //     final result = await MineService.postCollect(widget.model.id ?? '', LoadDataType.post.collectType, !hasCollect);
          //     if (result) {
          //       widget.model.vidStatus?.hasCollected = !hasCollect;
          //       if (hasCollect) {
          //         widget.model.collectCount = collectCount - 1;
          //       } else {
          //         widget.model.collectCount = collectCount + 1;
          //       }
          //     }
          //     setState(() {});
          //   },
          //   child: Row(
          //     children: [
          //       Image.asset(
          //         widget.model.vidStatus?.hasCollected == true ? "collect_red.png".communityPath : "collect_empty_gray.png".communityPath,
          //         width: 20,
          //         height: 20,
          //       ),
          //       5.w.sizeBoxW,
          //       Text(
          //         widget.model.collectCount?.humanizeFormatDefault("收藏") ?? '',
          //         style: TextStyle(color: Color(0xff989898), fontSize: 14.sp),
          //       ),
          //     ],
          //   ),
          // ),
          Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Image.asset("count_msg_gray.png".communityPath, width: 20, height: 20),
              const SizedBox(width: 2),
              Text(
                widget.model.commentCount?.humanizeFormat ?? "",
                style: TextStyle(
                  color: Color(0xff999999),
                  fontSize: 12,
                ),
              ),
            ],
          ),
          40.sizeBoxW,
          GestureDetector(
            behavior: HitTestBehavior.translucent,
            onTap: () => Get.dialog(ShareVideoDialog(
              videoModel: widget.model,
            )),
            child: Row(
              children: [
                Image.asset(
                  'post_share_gray.png'.communityPath,
                  width: 20,
                  height: 20,
                ),
                4.w.sizeBoxW,
                Text(
                  '分享',
                  style: TextStyle(color: Color(0xff989898), fontSize: 14.sp),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
